<?php
/**
 * 用户后台首页文件
 *
 * @author		Arthur(ArthurXF@gmail.com)
 * @copyright	(c) 2006 by bizeway.com
 * @version		$Id$
 * @package		ArthurXF
 */

error_reporting(0);
require_once('../config/config.inc.php');
require_once("../class/deal.class.php");
//$blJump = 0;
require_once("../../useradmin/checklogin.php");
$objWebInit =& new deal();
//数据库连接参数
$objWebInit->setDBG($arrGPdoDB);
//smarty参数
$objWebInit->arrGSmarty = $arrGSmarty;
//翻页参数
$objWebInit->arrGPage = $arrGPage;
$objWebInit->db();

if (empty($_GET['page'])) {
	$intPage = 1 ;
} else {
	$intPage = intval($_GET['page']);
}

$arrWhere = array();
$arrLink = array();

$intUserID = $_SESSION['user_id'];


$strWhere = '  where user_id = '.$intUserID.' order by submit_date desc';

//取得会员个人订单信息

$limit =' limit '.($intPage-1)*$arrGPage['page_size'].','.$arrGPage['page_size'];
$arrDealInfo = array();
$arrDealInfo = $objWebInit->getInfoList($strWhere);
$intRowsNum = $arrDealInfo['COUNT_ROWS'];
unset($arrDealInfo['COUNT_ROWS']);

//翻页跳转link
$strLink = '';
if (!empty($arrLink)) $strLink = implode('&',$arrLink);
$strPage= $objWebInit->makeInfoListPage($intRowsNum,$strLink);

//替换显示订单状态
foreach($arrDealInfo as $k=>$v){
	foreach($arrGDealState as $kk=>$vv){
		if($arrDealInfo[$k]['state'] == $kk){
			$arrDealInfo[$k]['state'] = $vv;
		}
	}		
}


if ($_SERVER["REQUEST_METHOD"] == "POST"){
		//id[]处理
		$strId=implode(",",$_POST["id"]);
		$strId="(".$strId.")";			

		if($_POST['id'] == ''){			
			check::Alert('请选择订单',-1);
		}		
		$arrInfo = $objWebInit->getDeal($strId);
				
		if($arrInfo['state'] ==6){
			check::Alert('该订单已经完成，不能再操作',-1);
		}
		if($_POST['del'] !=''){
			if($arrInfo['type_id'] == 1){//当订单状态为：新订单,待确认 ,可以取消
				if($objWebInit->deleteDeal($strId)){
					check::Alert('取消订单成功',-1);
				} else {
					check::Alert('取消订单失败',-1);
				}
			}else{
				check::Alert('您无法取消订单，请跟商家联系！',-1);
			}
		}else{
			if($arrInfo['type_id'] != 5){//当订单状态为：新订单,待确认 ,可以取消
				if($objWebInit->SuccessDeal($strId)){
					check::Alert('交易成功',-1);
				} else {
					check::Alert('交易失败',-1);
				}
			}else{
				check::Alert('此订单已经交易成功！',-1);
			}			
		}
}

//全站公用block
@include '../../_block.php';

//输出到模板
$arrMOutput["smarty_assign"]['arrData'] = $arrDealInfo;
$arrMOutput["smarty_assign"]['strPage'] = $strPage;
$arrMOutput["smarty_assign"]['MAIN'] = $arrGSmarty['adminu_main_dir'].'my_deal.html';
$objWebInit->output($arrMOutput);
?>